package com.chenyun.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.chenyun.common.annotation.Page;
import com.chenyun.satoken.starter.annotation.SaCheckAdmin;
import com.chenyun.system.model.SysLogininfor;
import com.chenyun.system.service.ISysLogininforService;
import com.chenyun.boot.web.controller.BaseController;
import com.chenyun.common.vo.AjaxResult;
import com.chenyun.common.vo.LoginLog;
import com.chenyun.common.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统访问记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/logininfor")
@Api(tags = "用户登录日志-admin")
@SaCheckAdmin
public class SysLogininforController extends BaseController<ISysLogininforService, SysLogininfor> {
    @Resource
    private ISysLogininforService logininforService;

    @ApiOperation("获取列表")
    @PostMapping("/list")
    @SaCheckPermission("system:loginlog:list")
    @Page
    public PageResult list(@RequestBody  SysLogininfor logininfor) {
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        return getDataTable(list);
    }

    @ApiOperation("删除")
    @PostMapping("del")
    @SaCheckPermission("system:loginlog:del")
    public AjaxResult remove(@RequestBody Long[] infoIds) {
        return toAjax(logininforService.deleteLogininforByIds(infoIds));
    }

    @ApiOperation("清除用户登录日志-全部")
    @PostMapping("/clean")
    @SaCheckPermission("system:loginlog:clean")
    public AjaxResult clean() {
        logininforService.cleanLogininfor();
        return AjaxResult.SUCCESS();
    }


    @PostMapping("insertLoginLog")
    public AjaxResult insertLoginLog(@RequestBody LoginLog log) {
        SysLogininfor logininfor = new SysLogininfor();
        BeanUtil.copyProperties(log, logininfor);
        return toAjax(logininforService.insertLogininfor(logininfor));
    }


}
